require('module-alias/register')

const Koa = require('koa')
const parser = require('koa-bodyparser')
const path = require('path')
const InitManager = require('./core/init')
const catchError = require('./middlewares/exception')
const static = require('koa-static')
const cors = require('koa-cors')
const redis = require("redis");


const redisClient = redis.createClient({
    port: 6379,
    host: '127.0.0.1'
})

redisClient.on('error', err => {
    console.error('Redis Client Error', err);
})

redisClient.on('connect', () => {
    console.log('Redis Client Connected');
})



const app = new Koa()
// Session配置
app.use(cors())
app.use(catchError)
app.use(parser())
app.use(static(path.join(__dirname, './static')))
app.use(static(path.join(__dirname, './uploadFiles')))
// 服务public目录下的静态文件
app.use(static(path.join(__dirname, 'public')));
const redisInstance = redisClient; // 存储Redis客户端对象的全局变量


InitManager.initCore(app)

app.listen(3000)
